package parse

import (
	"Crawlab/common/engine/os"
	"regexp"
)

const forumListRegexp = `<a href="(bbs\.forum\.[\d]+\.html)"[^>]*>([^<]+)</a>`

// 论坛列表匹配结果.
func ForumListParseResult(content []byte) os.ParseResult {
	compile := regexp.MustCompile(forumListRegexp)
	matchArray := compile.FindAllSubmatch(content, -1)

	parseResult := os.ParseResult{}

	for _, singleArray := range matchArray {
		// 数组内容: [完整连接, 连接, 版块名]

		parseResult.Items = append(parseResult.Items, "Forum "+string(singleArray[2]))
		parseResult.Requests = append(parseResult.Requests, os.Request{
			Url:       "https://hu60.cn/q.php/" + string(singleArray[1]),
			ParseFunc: ForumParseResult,
		})
	}

	return parseResult
}
